<?php
namespace app\index\controller;


use think\Controller;

/**
 * Class Index
 * @package app\index\controller
 * 前台首页控制器
 */
class Index extends Common
{
    //前台主页
    public function index()
    {
        //1.处理标签页title
        $conf = ['title'=>'博客-首页'];
        //2.处理文章数据
        $data = db('article')
            ->alias('a')
            ->join('__CATEGORY__ c','a.category_cid = c.cid')
            ->where('is_recycle',1)
            ->order('sendtime desc')
            ->paginate(3);
        //3.获取分页显示
        $page = $data->render();
        //4.转为数组
        $data = $data->toArray();
        $data = $data['data'];
        foreach ($data as $k=>$v){
            $data[$k]['tags'] = db('article_tag')
                ->alias('at')
                ->join('__TAG__ t','at.tag_tid = t.tid')
                ->where('at.article_aid',$v['aid'])
                ->field(['t.tid,t.tname'])
                ->select();
        }
        //模板变量赋值
        $this->assign('data', $data);
        $this->assign('page', $page);
        $this->assign('conf',$conf);
        //1视图
        return view();
    }
}
